#include "CubeMapSample.h"
#include "DirectXTK\DDSTextureLoader.h"
CubeMapSample::CubeMapSample(ID3D11Device* device, ID3D11DeviceContext* context)
	: SampleBase(device,context)
{
    m_states = std::make_unique<CommonStates>(device);

    m_effect = std::make_unique<EnvironmentMapEffect>(device);
    m_effect->EnableDefaultLighting();

    m_shape = GeometricPrimitive::CreateSphere(context);
    m_shape->CreateInputLayout(m_effect.get(),
        m_inputLayout.ReleaseAndGetAddressOf());

    DX::ThrowIfFailed(
        CreateDDSTextureFromFile(device, L"../Resources/Textures/wood.dds", nullptr,
            m_texture.ReleaseAndGetAddressOf()));

    m_effect->SetTexture(m_texture.Get());

    DX::ThrowIfFailed(
        CreateDDSTextureFromFile(device, L"../Resources/Textures/cubemap.dds", nullptr,
            m_cubemap.ReleaseAndGetAddressOf()));

    m_effect->SetEnvironmentMap(m_cubemap.Get());

    m_world = Matrix::Identity;
    m_view = Matrix::CreateLookAt(Vector3(2.f, 2.f, 2.f),
        Vector3::Zero, Vector3::UnitY);
    m_proj = Matrix::CreatePerspectiveFieldOfView(XM_PI / 4.f,
       16.0/9.0f, 0.1f, 10.f);

    m_effect->SetView(m_view);
    m_effect->SetProjection(m_proj);
}

CubeMapSample::~CubeMapSample()
{
}

void CubeMapSample::Update(float dt)
{
}

void CubeMapSample::Render()
{
    m_effect->SetWorld(m_world);
    m_shape->Draw(m_effect.get(), m_inputLayout.Get(), false, false, [=] {
        auto sampler = m_states->LinearWrap();
        m_context->PSSetSamplers(1, 1, &sampler);
        });
}

void CubeMapSample::GUI()
{
}

void CubeMapSample::DrawFont()
{
}
